<?php

    namespace app\admin\controller;
    use think\Controller;
    use app\admin\model\Teacher;
    use app\admin\model\Course;
    use think\Request;
    use think\Db;
    use app\Admin\model\Do_change;

    class User extends Controller{


        public function index(){
            //volist遍历数据库
            $role = New Teacher();
            $data = $role -> t_list();
            //dump($data->toArray());
            $this->assign('t_list',$data);

            
            //修改教师信息
            if(request()->isPost()){
                $do_change=new Do_change();
                $data=input('post.');
                // var_dump($data);
                $num=$do_change->index($data);
                
                if($num==1){
                    $this->success("修改成功","admin/user/index");
                }else{
                    $this->error('修改失败');
                }
            }

            //修改教师信息里面的课程遍历volist
            $course = New Course();
            $change_coursendata = $course -> change_coursen_list();
            //dump($data->toArray());
            $this->assign('change_coursen_list',$change_coursendata);



            return $this->fetch();
        }

        public function userdelete(Request $Request){
            $id = request()->param();
            // var_dump($id);
            
            $res = DB::table("teacher")->delete($id);
            if($res){
                $this->success("OK","admin/user/index");
            }else{
                $this->error();
            }
        }

        public function userinsert(){
            if(request()->isPost()){
                $teacher=new Teacher();
                $data=input('post.');
                // var_dump($data);
                $num=$teacher->insert($data);
                if($num==1){
                    $this->success("新添成功","admin/user/index");
                }else{
                    $this->error('新添失败');
                }
            }
            return $this->fetch();
        }



    }

?>